$(function () {
    getIndex()
})

function getIndex() {
    $.ajax({
        url: '/my/userinfo',
        type: 'get',
        success: function (set) {
            // console.log(set);
            getAvatar(set.data)
        }
    })
}

function getAvatar(data) {
    uname = data.nickname || data.username
    $('#welcome').html('欢迎' + uname)
    if (data.user_pic == null) {
        $('.text-avatar').show().html(uname[0].toUpperCase())
        $('.layui-nav-img').hide()
    } else {
        $('.text-avatar').hide()
        $('.layui-nav-img').show().attr('src', data.user_pic)
    }
}

var layer = layui.layer
$('#btnLogout').on('click', function () {
    layer.confirm('确定退出登录?', { icon: 3, title: '提示' }, function (index) {
        localStorage.removeItem('token')
        location.href = '/login.html'
        layer.close(index)
    })
})